export default defineNuxtRouteMiddleware(async (to, from) => {
  if (process.server) return
  const nuxtApp = useNuxtApp()
  let user
  try {
    user = nuxtApp.$lc.currentUser()
  } catch (e) {
    user = null
  }
  if (!user) {
    const backUrl = useBackUrl()
    backUrl.value = to.path
    // 将正确的Nuxt上下文应用于我们的`navigateTo`调用。
    return nuxtApp.runWithContext(() => navigateTo('/login'))
  }
})
